package com.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.sfzy.entity.PsychReply;
import com.sfzy.service.PsychReplyService;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PsychReplyController
 * @Description TODO
 * @Author niejiacan
 * @Date 2025年08月14日 9:40
 * @Version 1.0
 */
@RestController
@RequestMapping("psychReply")
public class PsychReplyController {
    @Autowired
    private PsychReplyService psychReplyService;

    @PostMapping
    public R addPsychReply(@RequestBody PsychReply psychReply){
        int i = psychReplyService.addPsychReply(psychReply);
        if (i==0){
            return R.fail();
        }
        return R.ok();
    }

    @PutMapping
    public R updatePsychReply(@RequestBody PsychReply psychReply){
        int i = psychReplyService.updatePsychReply(psychReply);
        if (i==0){
            return R.fail();
        }
        return R.ok();
    }

    @DeleteMapping("{id}")
    public R deletePsychReply(@PathVariable("id") int id){
        int i = psychReplyService.deletePsychReply(id);
        if(i==0){
            return R.fail();
        }
        return R.ok();
    }

    @GetMapping("{id}")
    public R seletePsychReply(@PathVariable("id") int id){
        PsychReply psychReply = psychReplyService.selectPsychReply(id);
        return R.ok(psychReply);
    }

    @GetMapping("page2")
    public R pageReplyContent2(PsychReply psychReply,
                             @RequestParam(required = false,defaultValue = "1")int pageNum,
                             @RequestParam(required = false,defaultValue = "5")int pageSize){
        PageInfo<PsychReply> psychReplyPageInfo = psychReplyService.pageReplyContent2(psychReply, pageNum, pageSize);
        return R.ok(psychReplyPageInfo);
    }













}
